package com.baizhi.hospital.service.impl;

import com.baizhi.hospital.annotation.LogAnnotation;
import com.baizhi.hospital.dao.PatientDao;
import com.baizhi.hospital.entity.Patient;
import com.baizhi.hospital.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PatientServiceImpl implements PatientService {
    @Autowired(required = false)
    private PatientDao patientDao;
    @Override
    //@LogAnnotation(value = "查询患者信息",type = "selectPatientByPage")
    public Map selectPatientByPage(int page, int limit, String cc) {
        if(cc==null||cc==" "){
            cc=null;
        }else{
            cc="%"+cc+"%";
        }
        int offset=(page-1)*limit;
        int count=patientDao.selectPatientCount(cc);
        List<Patient> patients = patientDao.selectPatientByPage(offset, limit, cc);
        Map map=new HashMap();
        map.put("msg","");
        map.put("code",0);
        map.put("count",count);
        map.put("data",patients);
        return map;
    }

    @Override
    //@LogAnnotation(value = "添加患者信息",type = "insert")
    public Map insert(Patient patient) {
        Map map=new HashMap();
        int count = patientDao.insert(patient);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "删除患者信息",type = "delete")
    public Map delete(int patientId) {
        Map map=new HashMap();
        int count = patientDao.delete(patientId);
        if(count>0){
            map.put("isDelete",true);
        }else{
            map.put("isDelete",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "批量删除患者信息",type = "multiDelete")
    public Map multiDelete(int[] ids) {
        Map map=new HashMap();
        int count = patientDao.multiDelete(ids);
        if(count>0){
            map.put("isMultiRemove",true);
        }else{
            map.put("isMultiRemove",false);
        }
        return map;
    }

    @Override
    //@LogAnnotation(value = "查询患者信息",type = "selectOnePatient")
    public Patient selectOnePatient(int patientId) {
        return patientDao.selectOnePatient(patientId);
    }

    @Override
    //@LogAnnotation(value = "更新患者信息",type = "update")
    public Map update(Patient patient) {
        Map map=new HashMap();
        int count = patientDao.update(patient);
        if(count>0){
            map.put("isUpdate",true);
        }else{
            map.put("isUpdate",false);
        }
        return map;
    }
}
